package com.example.test.controller;

import com.example.test.bean.OrderInfoBO;
import com.example.test.service.WybzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Controller
public class WybzController {

    @Autowired
    private WybzService wybzService;


    @RequestMapping("/wybz/index")
    public String index(){

        return "index";
    }

    @RequestMapping("/xszc/index1")
    public String index1(){

        return "index3";
    }


    @RequestMapping("/wybx/getData")
    @ResponseBody
    public List<OrderInfoBO> getData(){
        //添加当前时间
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
        String createTime = dateFormat.format(now);//格式化然后放入字符串中


        List<OrderInfoBO> orderInfoList = wybzService.getOrderInfoByCreateTime("2020-07-13");
        if (orderInfoList.size() == 0 || orderInfoList.isEmpty()){
            return new ArrayList<>();
        }else {
            return orderInfoList;
        }
    }

    @RequestMapping("/wybx/sendMsg")
    @ResponseBody
    public void sendMsg(){
        //添加3天前时间
//        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
//        String createTime = dateFormat.format(now);//格式化然后放入字符串中
        Calendar c = Calendar.getInstance();

        c.add(Calendar.DATE, - 5);

        Date time = c.getTime();

        String preDay = dateFormat.format(time);
        List<OrderInfoBO> orderInfoList = wybzService.getOrderInfoByCreateTime(preDay);

        wybzService.sendMsg(orderInfoList);

    }


}
